#region Summary

// 
// Owner : JackieHan 
// 
// Solution : UpdateSystem
// 
// Project :Project
// 
// File : UpdateSystemInfo.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 某个待更新的系统的全局配置
// 
// History : 
//			2011-01-05 10:23:06	    Create 
// 

#endregion

#region Using

using System.Linq;
using System.Collections.Generic;

#endregion

namespace Skomart.Update.Config.Server
{
    /// <summary> 
    /// 某个待更新的系统的全局配置
    /// </summary>
    public class UpdateSystemInfo
    {
        public UpdateSystemInfo()
        {
            PublishLogs = new Dictionary<string, PublishLogInfo>();
        }

        /// <summary>
        /// 系统名称
        /// </summary>
        public string SystemName { get; set; }
        /// <summary>
        /// 发布历史
        /// </summary>
        public IDictionary<string, PublishLogInfo> PublishLogs { get; set; }

        /// <summary>
        /// 根据系统版本号获取该版本号的发布记录
        /// </summary>
        /// <param name="version">发布时的版本号</param>
        /// <returns></returns>
        public PublishLogInfo this[string version]
        {
            get
            {
                return PublishLogs[version];
            }
        }

        /// <summary>
        /// 获取当前系统的最新的文件
        /// </summary>
        /// <returns></returns>
        public IList<UpdateFileInfo> GetNewFiles()
        {
            var files = new List<UpdateFileInfo>();
            var logs = PublishLogs.Values;
            foreach (var file in logs.OrderByDescending(log => log.Date)
                .SelectMany(log => log.Files.Where(file => !files.Any(f => f.Path == file.Path))))
            {
                files.Add(file);
            }
            return files.Where(f => f.OperateType != OperateType.Delete).ToList();
        }
    }
}